/**
 * 08/dic/2011 - fabio.melillo@gmail.com
 */
package demo.unisannio;

import org.unisannio.remote.GenericRemote;
import org.unisannio.remote.RemoteContentProvider;
import org.unisannio.util.MovieMetaData;

import android.app.Activity;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.AsyncTask;
import android.widget.Toast;

/**
 * @author fabio
 * 
 */
public class DeleteMoviesTask extends
		AsyncTask<GenericRemote, Integer, Integer> {

	private Activity activity;
	private ProgressDialog dialog;

	public DeleteMoviesTask(Activity activity) {
		this.activity = activity;
	}

	@Override
	protected void onPreExecute() {
		dialog = ProgressDialog.show(activity, "", "Querying. Please wait...",
				true);
	}

	@Override
	protected Integer doInBackground(GenericRemote... remote) {
//		String[] valori = new String[1];
//		TextView args = (TextView) activity.findViewById(R.id.whereArgs);
//		String arg = args.getText().toString();
//		valori[0] = arg;
		
		//bisogna inizializzare questo array
		String[] valori=null;
		String where = MovieMetaData.MOVIE_TITLE_KEY + " LIKE ? ";
		Uri uri = MovieMetaData.CONTENT_URI;
		int res = ((RemoteContentProvider) remote[0])
				.delete(uri, where, valori);

		return res;
	}

	@Override
	protected void onPostExecute(Integer num) {
		dialog.dismiss();
		Toast toast = Toast.makeText(activity, num + " record cancellati",
				Toast.LENGTH_SHORT);
		toast.show();

	}

}
